package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.Random;

import org.testng.annotations.Test;

import com.example.fw.datamapping.ContactLine;
import com.example.utils.SortedListOf;

public class ContactModificationTests extends TestBase{
	@Test (dataProvider = "randomValidContactGenerator")
	public void modifySomeContact(ContactData contact) {

		SortedListOf<ContactLine> oldContactLineList = app.getContactHelper().getContactLines();
		
		Random rnd = new Random();
		int index = rnd.nextInt(oldContactLineList.size()-1);
		ContactData oldContact = app.getContactHelper().modifyContact(index, contact);
				
		SortedListOf<ContactLine> newContactLinesList = app.getContactHelper().getContactLines();
		
		assertThat(newContactLinesList, equalTo(oldContactLineList.without(index).withAdded(oldContact.updateWithOtherContact(contact).toContactLine())));
	}
}